package com.highgain.displacementtrend.entity;

/**
 * 返回结果封装类
 *@author DingBaoyong
 *@date 2020/8/12 16:21
 **/
public class Result {
    private Integer flag = 1;
    private String msg;
    private Object obj;

    public Integer getFlag() {
        return flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getObj() {
        return obj;
    }

    public void setObj(Object obj) {
        this.obj = obj;
    }

    public Result() {
    }

    public Result(int flag, String msg) {
        this.flag = flag;
        this.msg = msg;
    }

    /**
     * 成功静态方法
     */
    public static Result ok(String msg) {
        Result r = new Result();
        r.setFlag(1);
        r.setMsg(msg);
        return r;
    }

    /**
     * 失败静态方法
     */
    public static Result error(String msg) {
        Result r = new Result();
        r.setFlag(0);
        r.setMsg(msg);
        return r;
    }

    public Result message(String message){
        this.setMsg(message);
        return this;
    }

    public Result data(Object obj){
        this.obj = obj;
        return this;
    }

    @Override
    public String toString() {
        return "Result{" +
                "flag=" + flag +
                ", msg='" + msg + '\'' +
                ", obj=" + obj +
                '}';
    }
}